<?php

namespace Drupal\shusy_product\ViewsController;

use Drupal\shusy_product\ViewsController\handler\field\ShusyProductEditLinkViewsField;
use Drupal\shusy_product\ViewsController\handler\field\ShusyProductStandardsViewsField;
use Drupal\shusy_product\ViewsController\handler\field\ShusyProductStatusViewsField;
use Drupal\shusy_product\ViewsController\handler\field\ShusyProductVipViewsField;
use Drupal\shusy_product\ViewsController\handler\filter\ShusyProductStatusViewsFilter;
use Drupal\shusy_product\ViewsController\handler\filter\ShusyProductVipViewsFilter;
use EntityDefaultViewsController;


class ShusyProductViewsController extends EntityDefaultViewsController {

  public function views_data() {
    $data = parent::views_data();
    if (!empty($this->info['base table'])) {
      $table = $this->info['base table'];
      $info = [];

      $info[$table]['edit_link'] = [
        'title' => t('编辑'),
        'help' => t('编辑.'),
        'field' => [
          'handler' => ShusyProductEditLinkViewsField::class,
        ],
      ];
      $info[$table]['status'] = [
        'title' => '状态 0 下架 1 上架',
        'help' => '状态 0 下架 1 上架',
        'real field' => 'status',
        'field' => [
          'handler' => ShusyProductStatusViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyProductStatusViewsFilter::class,
        ],
      ];
      $info[$table]['vip'] = [
        'title' => '允许VIP价格',
        'help' => '允许VIP价格(仅当产品属于VIP价格分类时有效) 0 否 1 是',
        'real field' => 'vip',
        'field' => [
          'handler' => ShusyProductVipViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyProductVipViewsFilter::class,
        ],
      ];

      $info[$table]['standards'] = [
        'title' => t('规格项'),
        'help' => t('规格项.'),
        'field' => [
          'handler' => ShusyProductStandardsViewsField::class,
          'type' => 'list<shusy_product_standard>',
        ],
      ];

      $data = drupal_array_merge_deep($data, $info);
    }
    return $data;
  }
}
